var log_id = '';
var teacherid = '';
$('#commentModal').on('show.bs.modal', function (e) {
    log_id = $(e.relatedTarget).attr('data-logid');
    teacherid = $(e.relatedTarget).attr('data-teacherid');
})

$('body').on('click', '#commentModalForm .form-group span', function() {
    var curIndex = $(this).index()-1;
    var $parent = $(this).parent();
    $parent.data('star', curIndex+1);
    var $span = $parent.find('span');
    $span.each(function(index, item) {
        if (index <= curIndex) {
            $(item).removeClass('star-off').addClass('star-on');
        } else {
            $(item).removeClass('star-on').addClass('star-off');
        }
    });

});

$('#commentModalForm .form-group span').mouseover(function() {
    var curIndex = $(this).index()-1;
    var $parent = $(this).parent();
    var $span = $parent.find('span');
    $span.each(function(index, item) {
        if (index <= curIndex) {
            $(item).removeClass('star-off').addClass('star-on');
        } else {
            $(item).removeClass('star-on').addClass('star-off');
        }
    });
});

$('#commentModalForm .form-group').mouseout(function() {
    var curIndex = $(this).data('star') || 0;
    var $span = $(this).find('span');
    $span.each(function(index, item) {
        if (index < curIndex) {
            $(item).removeClass('star-off').addClass('star-on');
        } else {
            $(item).removeClass('star-on').addClass('star-off');
        }
    });
});

$('#commentBtn').click(function() {
    var remark = $('#commentRemark').val();
    var total = $('[data-name=total]').data('star') || 0;
    if (remark.length > 80) {
        alert('评论内容不可超过80字');
        return false;
    }

    if (!total) {
        alert('必选选择总评分。');
        return false;
    }
    var $form = $('#commentModalForm .form-group');
    var data = {
        total: $('[data-name=total]').data('star') || 0,
        accuracy: $('[data-name=accuracy]').data('star') || 0,
        enrich: $('[data-name=enrich]').data('star') || 0,
        easy: $('[data-name=easy]').data('star') || 0,
        experience: $('[data-name=experience]').data('star') || 0,
        fast: $('[data-name=fast]').data('star') || 0,
        remark: remark,
        log_id: log_id,
        user_id: teacherid
    };
    $.ajax({
        url: '/Home/Order/addComment',
        type: 'post',
        data: data,
        dataType: 'json'
    })
    .done(function(res) {
        if (res.error) {
            res.msg && alert(res.msg);
        }
        else {
            location.reload();
        }
    });
});

// 老师详情hover效果
$('.table-condensed .remark-detail').popover();

// 评价详情hover效果
$('.table-condensed .comment-detail').popover();

